﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.IO;

namespace Util
{
    public class XmlUtil
    {
        public static void XmlSerialize(object type, string fileName)
        {
            XmlSerializer xs = new XmlSerializer(type.GetType());
            Stream stream = new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Read);
            xs.Serialize(stream, type);
            stream.Close();
        }

        public static object XmlDeserialize(Type type, string fileName)
        {
            XmlSerializer xs = new XmlSerializer(type);
            Stream stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
            object list = xs.Deserialize(stream) as object;
            stream.Close();
            return list;
        }
    }
}
